<?php

/**
 * paciente actions.
 *
 * @package    gestdent
 * @subpackage paciente
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class pacienteActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->filtro = new GestdentPacienteFormFilter();
    $this->gestdent_paciente_list = GestdentPacientePeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->gestdent_paciente = GestdentPacientePeer::retrieveByPk($request->getParameter('id'));
    $this->forward404Unless($this->gestdent_paciente);
    //$this->gestdent_paciente = $this->getRoute()->getObject();
    $this->getUser()->addPacienteToHistory($this->gestdent_paciente);
    $this->getUser()->setSessionPaciente($this->gestdent_paciente);
  
  }

  public function executeShow2(sfWebRequest $request)
  {
    $this->gestdent_paciente = GestdentPacientePeer::retrieveByPk($request->getParameter('id'));
    $this->forward404Unless($this->gestdent_paciente);
    //$this->gestdent_paciente = $this->getRoute()->getObject();


  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new GestdentPacienteForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new GestdentPacienteForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($gestdent_paciente = GestdentPacientePeer::retrieveByPk($request->getParameter('id')), sprintf('Object gestdent_paciente does not exist (%s).', $request->getParameter('id')));
    $this->form = new GestdentPacienteForm($gestdent_paciente);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($gestdent_paciente = GestdentPacientePeer::retrieveByPk($request->getParameter('id')), sprintf('Object gestdent_paciente does not exist (%s).', $request->getParameter('id')));
    $this->form = new GestdentPacienteForm($gestdent_paciente);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($gestdent_paciente = GestdentPacientePeer::retrieveByPk($request->getParameter('id')), sprintf('Object gestdent_paciente does not exist (%s).', $request->getParameter('id')));
    $gestdent_paciente->delete();

    $this->redirect('paciente/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $gestdent_paciente = $form->save();

      $this->redirect('paciente/edit?id='.$gestdent_paciente->getId());
    }
  }

  public function executeFiltrar(sfWebRequest $request)
  {
    $this->filtro = new GestdentPacienteFormFilter();
    // Construye un objeto criteria con el valor de los filtros
    $criteria = $this->filtro->buildCriteria($request->getParameter('gestdent_paciente_filters'));
    $this->gestdent_paciente_list = GestdentPacientePeer::doSelect($criteria);
    $this->setTemplate('search');
  }

  public function executeFiltrar2(sfWebRequest $request)
  {
    $this->filtro = new GestdentPacienteFormFilter();
    // Construye un objeto criteria con el valor de los filtros
    $criteria = $this->filtro->buildCriteria($request->getParameter('gestdent_paciente_filters'));
    $this->gestdent_paciente_list = GestdentPacientePeer::doSelect($criteria);
    $this->setTemplate('search2');
  }

  public function executePds(sfWebRequest $request)
  {
      $this->getUser()->getAttributeHolder()->remove('paciente_history2');
  }

  public function executeSearch(sfWebRequest $request)
  {
    $this->filtro = new GestdentPacienteFormFilter();

    //$criterio = new Criteria();
    //$criterio->add(GestdentPacientePeer::ID, 0);
    //$this->gestdent_paciente_list = GestdentPacientePeer::doSelect($criterio);
  }

  public function executeSearch2(sfWebRequest $request)
  {
    $this->filtro = new GestdentPacienteFormFilter();

    //$criterio = new Criteria();
    //$criterio->add(GestdentPacientePeer::ID, 0);
    //$this->gestdent_paciente_list = GestdentPacientePeer::doSelect($criterio);
  }

}
